<%--
  Created by IntelliJ IDEA.
  User: B饭老司机
  Date: 2024/3/23
  Time: 17:31
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="myUtil.personCheck" %>
<%@ page import="java.sql.*" %>
<%@ page import="myUtil.personCheck" %>
<html>
<head>
    <title>person_save</title>
</head>
<body>
<%
    String I = request.getParameter("id");
    int i = Integer.parseInt(I);
    String worknumber = request.getParameter("worknumber");
    String name = request.getParameter("name");
    String department = request.getParameter("department");
    String worktime = request.getParameter("worktime");
    String degree = request.getParameter("degree");
    String profession = request.getParameter("profession");
    String title = request.getParameter("title");
    String phonenumber = request.getParameter("phonenumber");
    String address = request.getParameter("address");
    String introduction = request.getParameter("introduction");
    if (personCheck.checkNumber(worknumber) && personCheck.checkS(name) && personCheck.checkS(department) &&
            personCheck.checkS(degree) && personCheck.checkS(profession) && personCheck.checkS(title) && personCheck.checkPhonenumber(phonenumber)) {
        try{
            Connection conn = (Connection) session.getAttribute("Connection");
            String sql = "";
            if (i != 0) {
                sql = "update people set worknumber=?, name=?, department=?, worktime=?, degree=?, profession=?, title=?, phonenumber=?, address=?, introduction=? where id=" + i;
            }

            PreparedStatement preparedStatement = conn.prepareStatement(sql);
            preparedStatement.setString(1, worknumber);
            preparedStatement.setString(2, name);
            preparedStatement.setString(3, department);
            preparedStatement.setString(4, worktime);
            preparedStatement.setString(5, degree);
            preparedStatement.setString(6, profession);
            preparedStatement.setString(7, title);
            preparedStatement.setString(8, phonenumber);
            preparedStatement.setString(9, address);
            preparedStatement.setString(10, introduction);

            int rowsUpdated = preparedStatement.executeUpdate();
            if (rowsUpdated > 0) {

            } else {

            }
        }catch (SQLException e){

        }

        response.sendRedirect("person_list.jsp");
    } else {
        request.getRequestDispatcher("person_edit.jsp?id=" + i).forward(request, response);
    }

%>
</body>
</html>
